package com.sff.manager {
	import com.sff.core.sff_internal;
	import com.sff.system.LayerProvider;
	import com.sff.system.LayerSystem;
	
	import flash.sampler.DeleteObjectSample;
	import flash.utils.Dictionary;
	
	public class LayerManager {
		
		private var resizeManager	:ResizeManager;
		private var dicLayer		: Dictionary; 
		
		public function LayerManager(rm:ResizeManager) {
			resizeManager = rm;
			
			dicLayer = new Dictionary();
		}
		
		public function registerLayer(layerID:String):LayerSystem {			
			if (LayerProvider.sff_internal::hasLayer(layerID) == false) {
				
				var layer:LayerSystem = new LayerSystem(resizeManager);				
				LayerProvider.sff_internal::addLayer(layerID, layer);
				
				dicLayer[layerID] = layer;
				
				return layer;				
			}			
			return null;
		}
		
		public function unregisterLayer(layerID:String):void {			
			if (LayerProvider.sff_internal::hasLayer(layerID)) {
				LayerProvider.sff_internal::removeLayer(layerID);
				
				delete dicLayer[layerID];
			}
		}
		
		public function getLayerByID(layerID:String = null): LayerSystem {			
			if (LayerProvider.sff_internal::hasLayer(layerID)) {
				return LayerProvider.sff_internal::getLayer(layerID);								
			}			
			return null;
		}
		
		public function dispose(): void {			
			for (var layerID:String in dicLayer) {				
				unregisterLayer(layerID);
			}
			
			dicLayer = null;			
			resizeManager = null;
		}		
	}
}